-- =============================================
-- Author:		<Huynh Quoc Thanh>
-- Create date: <01/28/2010>
-- Description:	<Delete TimeSheet Record Store Procedure>
-- =============================================
USE TimeSheet
GO

IF EXISTS (SELECT * FROM sys.objects WHERE type = 'P' AND name = 'usp_DeleteTimeSheetByID')
	DROP PROCEDURE usp_DeleteTimeSheetByID
GO

CREATE PROCEDURE usp_DeleteTimeSheetByID
	@TimeSheetID BIGINT
AS
BEGIN 
	-- StatusID = 2 means Pending.
	IF EXISTS (SELECT TimeSheetID FROM TS_TimeSheet WHERE TimeSheetID = @TimeSheetID AND StatusID != 2)
		BEGIN
			DELETE FROM TS_TimeSheet WHERE TimeSheetID = @TimeSheetID
		END
	ELSE
		RAISERROR('This record is not exist or is approved!!',11,1)
END 